package com.woniuxy.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.woniuxy.entity.Shop;
import com.woniuxy.entity.User;
import com.woniuxy.mapper.UserMapper;
import com.woniuxy.service.UserService;
import com.woniuxy.utils.GUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {
    @Autowired
    private UserMapper userMapper;
    @Override
    public int add(User user) {
        return userMapper.insert(user);
    }

    @Override
    public void update(User user) {
        userMapper.update(user);
    }

    /**
     * 重写删除为逻辑删除
     * @param id
     */
    @Override
    public void delete(int id) {
        userMapper.deleteById(id);
    }

    /**
     * @Author Mr.Cai
     * 动态查找用户信息
     * @param user
     * @return
     */
    @Override
    public List<User> getByCondition(User user) {
        return userMapper.getByCondition(user);
    }

    @Override
    public User getByAccount(String account) {
        User user=userMapper.getByAccount(account);
        return user;
    }

    @Override
    public List<User> getAll(){
       return userMapper.getAll();
    }

    @Override
    public void register(String name, String password, String email) {
        User user = new User();
        user.setAvater("xxx");
        user.setName(name);
        user.setPassword(password);
        user.setScore(0);
        user.setRegisterTime(GUtils.getNow());
        user.setEmail(email);
        user.setCaptcha("c");
        user.setStatus("y");
        userMapper.insert(user);
    }

    @Override
    public void updatePsw(String name, String password) {
        User user = new User();
        user.setName(name);
        user.setPassword(password);
        userMapper.updateByName(user);
    }

    @Override
    public int getNameCount(String name) {
        return userMapper.getNameCount(name);
    }

    @Override
    public int getEmileCount(String email) {
        return userMapper.getEmileCount(email);
    }

    @Override
    public List<Shop> getShopByUserId(int id) {
        return userMapper.getShopByUserId(id);
    }

    @Override
    public int collectIsExist(int userId, int shopId) {
        return userMapper.collectIsExist(userId,shopId);
    }

    @Override
    public void collectShop(int userId, int shopId) {
        userMapper.collectShop(userId, shopId);
    }

    @Override
    public void noCollectShop(int userId, int shopId) {
        userMapper.noCollectShop(userId, shopId);
    }

}
